<?php
require('set.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>User-Center</title>
<link rel="stylesheet" href="/ast/messageop.css">
</head>
<body>
<style>
</style>
<section class="rt_wrap content mCustomScrollbar">
<div class="rt_content">
 <div class="container">
        <h1>消息中心</h1>
        <div class="cards-container">
        </div>
    </div>
</div>
</section>
</body>
</html>
<script>
	(function($){
		$(window).load(function(){
			$("a[rel='load-content']").click(function(e){
				e.preventDefault();
				var url=$(this).attr("href");
				$.get(url,function(data){
					$(".content .mCSB_container").append(data); 
					$(".content").mCustomScrollbar("scrollTo","h2:last");
				});
			});		
			$(".content").delegate("a[href='top']","click",function(e){
				e.preventDefault();
				$(".content").mCustomScrollbar("scrollTo",$(this).attr("href"));
			});	
		});
	})(jQuery);
</script>
<script>
	var userid = sessionStorage.getItem("user");
function messagelistshow(){
	loading_load_show();
	fetch('ht/message.php?userid='+userid)
	.then(response => response.json())
	.then(data => {
		const cardsContainer = document.querySelector('.cards-container');
		data.forEach(message => {
        const card = document.createElement('div');
        card.className = 'card';
		if(message.type === 'reader'){
        card.innerHTML = `
            <h2>读者反馈</h2>
            <p>${message.idea}</p>
            <time>${message.time}</time>
        `;
		}else{
			card.innerHTML = `
				<h2>系统消息</h2>
				<p>${message.idea}</p>
				<time>${message.time}</time>
				`;
		}
        card.addEventListener('click', () => {
            alert(`${message.idea}`);
        });
        cardsContainer.appendChild(card);
    });
	});
	loading_load_hide();
}
document.addEventListener('DOMContentLoaded', function() {
	messagelistshow();
});
</script>
